Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for array output and by reference #198

Merged
merged 11 commits into from
Jan 7, 2025
Merged

Conversation

stevenbrix
Copy link
Collaborator

adds final support for arrays, by supporting output and reference arrays.

These two implementations are fairly similar, so that's why i did them in one go. The only difference is that for output arrays the callee allocates the buffer (via CoTaskMemAlloc) and in reference arrays, the caller pre-allocates the buffer and it is filled in by the callee. Since Swift doesn't have true "out" params, the APIs for these on the Swift side are identical (both inout [T]) which could lead to some confusion. Possible improvement may be to use something like ArraySlice for reference arrays?

Changes

  1. Update Array+ToABI.swift to support allocating+filling a WinRT buffer.
  2. Updates Array+ToABI.swift to use the same WinRTArrayABI typealias that Array+FromAbi.swift uses. This made code-gen simpler
  3. For non-blittable reference arrays, we have to copy the buffer back into the swift array.
  4. Had to undef GetGlyphIndices as this conflicts with Win2D API (would love to not use any Windows headers!!)
  5. Cleaned up can_write.h since we now can generate the full projection. It only exists to not include APIs which were filtered out.

Arc builds/runs with the needed changes to remove the handwritten APIs we created due to lack of array support in swift-winrt.

@stevenbrix stevenbrix requested a review from a team as a code owner January 3, 2025 18:37
@tristanlabelle
Copy link
Contributor

For "fill" arrays, I was thinking UnsafeRawMutableBuffer<T> is the closest shape in Swift until we get https://forums.swift.org/t/se-0447-span-safe-access-to-contiguous-storage/74676?page=3 .

swiftwinrt/code_writers.h Show resolved Hide resolved
swiftwinrt/Resources/Support/Array+ToAbi.swift Outdated Show resolved Hide resolved
@stevenbrix
Copy link
Collaborator Author

For "fill" arrays, I was thinking UnsafeRawMutableBuffer is the closest shape in Swift until we get https://forums.swift.org/t/se-0447-span-safe-access-to-contiguous-storage/74676?page=3 .

@tristanlabelle wouldn't ArraySlice be just as appropriate in the meantime then?

@stevenbrix stevenbrix enabled auto-merge (squash) January 7, 2025 17:45
@stevenbrix stevenbrix merged commit 35e2ea1 into main Jan 7, 2025
1 check passed
@stevenbrix stevenbrix deleted the steve/array-output branch January 7, 2025 17:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants